# 读取entities里面的各个实体类文件，写入entities.yml和vocabulary.txt，并合并nlu_base.yml和entities.yml
labels = ['Check', 'Department', 'Disease', 'Drug', 'Food', 'Producer', 'Symptom']
with open('data/entities.yml', 'w', encoding='utf-8') as file_entities:
    pass  # 不需要写入任何内容，因为打开文件时内容已经被清空了
with open('data/vocabulary.txt', 'w', encoding='utf-8') as file_vocabulary:
    pass  # 不需要写入任何内容，因为打开文件时内容已经被清空了

file_vocabulary = open('data/vocabulary.txt', 'a', encoding='utf-8')
for i in range(len(labels)):
    with open('data/entities.yml', 'a', encoding='utf-8') as file_entities:
        file_entities.write(f"- lookup: {labels[i]}\n")
        file_entities.write(f"  examples: |\n")
        with open(f'data/entities/{labels[i]}.txt', "r", encoding="utf-8") as file_read:
            lines = file_read.readlines()
            for read_line in lines:
                file_entities.write(f"    - {read_line}")
                file_vocabulary.write(f"{read_line}")
            file_entities.write(f"\n")

# 将基础的nlu与实体合并。
with open("data/old.yml", "r", encoding='utf-8') as file1:
    lines = file1.readlines()
    with open("data/nlu.yml", "w", encoding='utf-8') as file2:
        for item in lines:
            file2.write(item)
        file2.write("\n")


with open("data/entities.yml", "r", encoding='utf-8') as file3:
    lines = file3.readlines()
    with open("data/nlu.yml", "a", encoding='utf-8') as file4:
        for item in lines:
            file4.write(item)